/**
 * Created by Shiun on 2018/5/8.
 */
$(function () {
    $('#modify-btn').on('tap', function () {
        var password = $.trim($('[name="password"]').val());
        var newPass = $.trim($('[name="newPass"]').val());
        var againnewPass = $.trim($('[name="againnewPass"]').val());
        var vCode = $.trim($('[name="vCode"]').val());

        if(!password){
            mui.toast('请输入原密码');
            return;
        }
        if(newPass != againnewPass){
            mui.toast('两次输入的密码不一致');
            return;
        }

        $('#modify-btn').on('tap',function(){
            $.ajax({
                url:'/user/updatePassword',
                type:'post',
                data:{
                    oldPassword: password,
                    newPassword: newPass,
                    vCode: vCode
                },
                success: function (res) {
                    if(res.success){
                        mui.toast("修改密码成功");
                        setTimeout(function () {
                            location.href = "login.html"
                        },1000)
                    }
                }
            })
        })


    })
    $('#getCode').on('tap',function () {
        $.ajax({
            url:'/user/vCodeForUpdatePassword',
            type:'get',
            success: function (res) {
                console.log(res.vCode);
            }
        })
    })
})
